Skip to content

fix(nextjs): Don't abort Cache Components renders on Cloudflare Workers when requests overlap - #25315

Merged
chargome merged 5 commits into
developfrom
js-3906-continue-work
Nov 4, 2026
Merged

chargome merged 5 commits into
developfrom
js-3906-continue-work

Conversation

@chargome

@chargome chargome commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

What

Fixes a bug where @sentry/nextjs on Cloudflare Workers broke Next.js Cache Components pages when two requests ran at the same time. One of the requests came back as an empty page.

Next.js has a check that fails a render when random values (like trace or span IDs) are generated during it. To avoid that, the SDK generates its IDs outside the render. On Cloudflare Workers that mechanism broke in two ways, both fixed here:

  • The SDK stepped out of the render using a snapshot that Cloudflare ties to a single request. When a second request reused it, the snapshot was rebuilt inside that request's render and triggered the check. The SDK now exits the Next.js render store directly, which Next.js 16.4 and newer expose on globalThis. On older Next.js versions the Cloudflare case stays as before.
  • @sentry/core only looks for the SDK hook once. On Cloudflare the Worker's copy of core generated its first ID before Next.js loaded and missed the hook forever. The Cloudflare entry of @sentry/nextjs now sets the hook up when the Worker starts.

Also adds an optional Cloudflare e2e variant for the Cache Components app with a test that fires overlapping requests.

Why

Users running Cache Components on Cloudflare Workers saw random pages fail under normal traffic, see #25245.

The new e2e variant is optional because released OpenNext does not run Cache Components renders on Cloudflare yet (opennextjs/opennextjs-cloudflare#1318). The fix was verified locally against their preview build of that PR.

Fixes #25245

@chargome chargome self-assigned this Oct 13, 2026
@linear-code

linear-code Bot commented Oct 13, 2026

Copy link
Copy Markdown

JS-3906

@chargome

Copy link
Copy Markdown
Member Author

bugbot run

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 0b6fa31 (PR test merge using develop at f2ee787)

Against: f2ee787 (develop) · base run #65001

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 30.4 kB - -
@sentry/browser - with treeshaking flags 28.54 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.43 kB - -
@sentry/browser (incl. Tracing) 52.72 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.72 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.69 kB - -
@sentry/browser (incl. Tracing, Replay) 93.02 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.61 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.76 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.75 kB - -
@sentry/browser (incl. Feedback) 47.98 kB - -
@sentry/browser (incl. sendFeedback) 35.5 kB - -
@sentry/browser (incl. FeedbackAsync) 40.61 kB - -
@sentry/browser (incl. Metrics) 31.44 kB - -
@sentry/browser (incl. Logs) 31.73 kB - -
@sentry/browser (incl. Metrics & Logs) 32.45 kB - -
@sentry/react 32.29 kB - -
@sentry/react (incl. Tracing) 55.09 kB - -
@sentry/vue 38.67 kB - -
@sentry/vue (incl. Tracing) 55.73 kB - -
@sentry/svelte 30.43 kB - -
@sentry/remix (Remix 3 client bundle) 57.8 kB - -
CDN Bundle 32.19 kB - -
CDN Bundle (incl. Tracing) 53.24 kB - -
CDN Bundle (incl. Logs, Metrics) 34.47 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.19 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 75.88 kB - -
CDN Bundle (incl. Tracing, Replay) 91.46 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.39 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.56 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.56 kB - -
CDN Bundle - uncompressed 94.67 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.63 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.14 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.37 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.71 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 279.32 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.05 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 293.03 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.74 kB - -
@sentry/nextjs (client) 58.04 kB - -
@sentry/sveltekit (client) 53.23 kB - -
@sentry/core/server 44.25 kB - -
@sentry/core/browser 13.93 kB - -
@sentry/node 155.71 kB +0.02% +18 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.26 kB - -
@sentry/node - without tracing 96.89 kB +0.02% +16 B 🔺
@sentry/node - without channel injection 136.04 kB +0.02% +20 B 🔺
@sentry/aws-serverless 105.11 kB +0.02% +21 B 🔺
@sentry/cloudflare (withSentry) - minified 200.67 kB - -
@sentry/cloudflare (withSentry) 499.05 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 222.65 kB +0.65% +1.42 kB 🔺

View base workflow run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 2 not successful, 41 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Failing after 1m Details
❌ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Failing after 4m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-eve Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 58s Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 52s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 5m Details
✅ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 48s Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 2m Details

chargome and others added 2 commits November 3, 2026 11:50
…rs when requests overlap

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…e Components E2E app

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@chargome
chargome force-pushed the js-3906-continue-work branch from d820bb9 to 6dcfd5b Compare November 3, 2026 10:52
@chargome

chargome commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6dcfd5b. Configure here.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@chargome
chargome marked this pull request as ready for review November 3, 2026 16:49
@chargome
chargome requested review from a team as code owners November 3, 2026 16:49
@chargome
chargome requested review from JPeer264, Lms24, andreiborza, logaretm, mydea, nicohrubec and s1gr1d and removed request for a team, Lms24, mydea, nicohrubec and s1gr1d November 3, 2026 16:49
@chargome
chargome removed the request for review from andreiborza November 3, 2026 16:49
chargome and others added 2 commits November 4, 2026 15:44
…ntry

Registers the runner at module scope of `@sentry/nextjs/cloudflare`, which runs at isolate startup before the
Worker's copy of `@sentry/core` generates its first ID. This restores the one-time runner resolution in core, so
SDKs without a runner don't look it up on every random value. Also leaves `traceLifecycle` unset in the Cache
Components Worker.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… Worker

On Workers the request transaction belongs to the `withSentry` client. The specs of this app wait for transaction
envelopes, so with span streaming in the Worker they time out even when the pages render (verified against the
OpenNext preview of opennextjs/opennextjs-cloudflare#1318).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@chargome
chargome requested a review from logaretm November 4, 2026 16:20
@chargome
chargome merged commit 1bd5136 into develop Nov 4, 2026
411 of 414 checks passed
@chargome
chargome deleted the js-3906-continue-work branch November 4, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@sentry/nextjs aborts Next.js Cache Components renders on Cloudflare Workers when requests overlap

3 participants